#pragma once

/*
 * redis connection pool.
 */
#include "redis_connection.h"
#include <queue>
#include <mutex>
#include <condition_variable>

namespace redisSpace {
	using redisConnectionPtr = std::shared_ptr<RedisConnection>;
	class RedisConnectionPool {
	public:
		RedisConnectionPool(const std::string& host, int port, std::string password, int index, int timeout, int poolSize);
		virtual ~RedisConnectionPool();

	public:
		redisConnectionPtr acquire();
		void release(redisConnectionPtr conn);

	private:
		void createPool();

	private:
		std::string host_;
		int port_;
		int index_;
		std::string password_;
		struct timeval timeout_;
		int poolSize_;

		std::queue<redisConnectionPtr> pool_;
		std::mutex mutex_;
		std::condition_variable condition_;
	};
}